﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SchoolYearClasses.ascx.cs" Inherits="Custom_SchoolYearClasses" %>
<script type="text/javascript">
    var schoolYearTerm = new Array();
    var showschoolClass = new Array();
    //当前选中学年
    var GetCurrentYear = 0;
    //当前选中学期
    var GetCurrentTerm = 0;
    //当前选中班级号
    var GetCurrentClass = 0;
    var OnChange=null;
//    //设置回调
//    function SetChange(obj)
//    {
//        OnChange = obj;
//    }
    
    function startChange1(y,t)
    {
        GetCurrentYear=y;
        GetCurrentTerm = t;
        
        var sel = document.getElementById("ClassSel");
        if(sel!=null)
        {
            sel.innerHTML="";
            
            for(var s=0;s<showschoolClass.length;s++)
            {
            
                if(showschoolClass[s].year == GetCurrentYear)
                {
                    for(var k=0;k<showschoolClass[s].classes.length;k++)
                    {
                        var oOption = document.createElement("OPTION");
                        oOption.text = showschoolClass[s].classes[k].ClsName;
                        oOption.value =showschoolClass[s].classes[k].ClsID;
                        
                        if(k == 0)
                        {
                            GetCurrentClass =  showschoolClass[s].classes[k].ClsID;
                            oOption.selected = true;
                        }
                        else
                        {
                            oOption.selected = false;
                        }
                        sel.add(oOption);  
                    }
                  
                    
                }
            }
        }

    }
    function startChange()
    {

        GetCurrentYear = event.srcElement.options[event.srcElement.selectedIndex].SchoolYear;
        GetCurrentTerm = event.srcElement.options[event.srcElement.selectedIndex].Term;


        var sel = document.getElementById("ClassSel");
        if(sel!=null)
        {
            sel.innerHTML="";
            
            for(var s=0;s<showschoolClass.length;s++)
            {
            
                if(showschoolClass[s].year == GetCurrentYear)
                {
                    for(var k=0;k<showschoolClass[s].classes.length;k++)
                    {
                        var oOption = document.createElement("OPTION");
                        oOption.text = showschoolClass[s].classes[k].ClsName;
                        oOption.value =showschoolClass[s].classes[k].ClsID;
                        
                        if(k == 0)
                        {
                            GetCurrentClass =  showschoolClass[s].classes[k].ClsID;
                            oOption.selected = true;
                        }
                        else
                        {
                            oOption.selected = false;
                        }
                        sel.add(oOption);  
                    }
                  
                    
                }
            }
        }
//        if(OnChange!=null)
//        {
//            OnChange(GetCurrentYear);
//        }
    }
    function InitSelect(selectId,year,term)
    {
        GetCurrentTerm = term;
        GetCurrentYear = year;
        var sel = document.getElementById(selectId);
        if(sel!=null)
        {
            for(i=0;i<schoolYearTerm.length;i++)
            {
                var oOption = document.createElement("OPTION");
                oOption.text = schoolYearTerm[i].Name;
                oOption.SchoolYear = schoolYearTerm[i].SchoolYear;
                oOption.Term = schoolYearTerm[i].Term;
                if(year == i)
                {
                    oOption.selected = true;
                }
                else
                {
                    oOption.selected = false;
                }
                sel.add(oOption);
            }
        }
    }
    function ClassChange()
    {
        GetCurrentClass=event.srcElement.value;
    }
</script>
学年：<select id="startYear" onchange="startChange()"></select>班级：
<select id="ClassSel" onchange="ClassChange()"></select>        
<script language="javascript">
 <%
        int index =0;
        foreach(Meqs.Entity.TermInfo y in terms)
        {
            Response.Write("schoolYearTerm["+index+"]={SchoolYear:"+y.SchoolYear+",Term:"+y.Term+",Name:'"+Common.ConvertYearAndTerm(y.SchoolYear,y.Term)+"'};");
            index++;
        }
        index = 0;
        foreach(ShowClasssinfo scinfo in showlasses)
        {
            Response.Write("showschoolClass["+index+"]={year:"+scinfo.year+"};");
            Response.Write("showschoolClass["+index+"].classes=new Array();");
            int vcindex = 0;
            foreach(Meqs.Entity.VClasssInfo vc in scinfo.classes)
            {
                string t = this.Server.HtmlDecode(vc.ClsName);
                t = t.Replace("\\", "\\\\");
                t = t.Replace("'", "\\'");
                t = t.Replace("<", "\\<");
                t = t.Replace(">", "\\>");
                Response.Write("showschoolClass["+index+"].classes["+vcindex+"]={ClsID:"+vc.RID+",ClsName:'"+t+"',Grade:"+vc.Grade+"};");
                vcindex++;
            }
            index++;
        }
        
        
        if(terms.Count>0)
        {
            Response.Write("InitSelect('startYear',"+terms[0].SchoolYear+","+terms[0].Term+");");
            Response.Write("startChange1("+terms[0].SchoolYear+","+terms[0].Term+");");
        }
        

 %>
 </script>